<?php
require_once('../model/m_qshifts.php');

class maintenance_qshifts{

	public $data = array();
	
	public function actionView(){
		$this->data = getQShifts();
		include_once("../views/v_session.php");		
		include_once("../views/v_header_principal_lev1.html");
		include_once("../views/v_maintenance_qshifts.html");
		include_once("../views/v_footer_principal.html");
	}
	
	public function actionAdd(){	
		include_once("../views/v_session.php");	
		include_once("../views/v_header_principal_lev1.html");
		include_once("../views/v_maintenance_qshifts_add.html");
		include_once("../views/v_footer_principal.html");	
	}

	public function actionAddQshift($new_role, $new_description){	
		if(addQshift($new_role, $new_description)){
			header("location:c_maintenance_qshifts.php?view=list");
			exit;				
		} else {		
			echo "<h1> Error creating Q-Shift</h1>";
			exit;
		}	
	}	
	
	public function actionEditQshift($qshiftid){		
		$current_qshift = array();
		$current_qshift = getQshift($qshiftid);
		
		///*** FALTA MANEJAR ROLE ID INEXISTENTE
		include_once("../views/v_session.php");		
		include_once("../views/v_header_principal_lev1.html");
		include_once("../views/v_maintenance_qshifts_edit.html");
		include_once("../views/v_footer_principal.html");
	}
	
	public function actionSaveQshiftEdit($qshiftid, $description){
		
		if(saveQshiftEdit($qshiftid, $description)){
			header("location:c_maintenance_qshifts.php?view=list");
			exit;
		}
		else {
			include_once("../views/v_session.php");		
			include_once("../views/v_header_principal_lev1.html");
			echo "<h1>THERE WAS A PROBLEM WHEN TRYING TO SAVE THE CHANGES!!!</h1>";
			include_once("../views/v_footer_principal.html");
		}	
	
	}
	
	public function actionDeleteQShift($qshiftid){
		
		if(deleteQShift($qshiftid)){
			header("location:c_maintenance_qshifts.php?view=list");
			exit;
		}
		else {
			include_once("../views/v_session.php");		
			include_once("../views/v_header_principal_lev1.html");
			echo "<h2>Unable to delete Queue Shift. Make sure the queue shift is not in use by any user.</h2>";
			echo "<br><br>";
			echo '<input type="button" value="Back" onclick="goBack();"/>';
			include_once("../views/v_footer_principal.html");
		}	
	
	}		
	
}

$instancia= new maintenance_qshifts;

if(isset($_GET['view'])){
	if($_GET['view']=="list")	
		$instancia->actionView();
}

if(isset($_GET['add'])){
	if($_GET['add']=="go")	
		$instancia->actionAdd();
}

if(isset($_GET['add_qshiftid'])){
		$instancia->actionAddQshift($_GET['add_qshiftid'],$_GET['description']);
}

if(isset($_GET['edit'])){
		$instancia->actionEditQshift($_GET['edit']);
}

if(isset($_GET['save_qshiftid'])){
		$instancia->actionSaveQshiftEdit($_GET['save_qshiftid'],$_GET['description']);
}


if(isset($_GET['delete'])){
		$instancia->actionDeleteQShift($_GET['delete']);
}
?>